
/*CGSS data can be applied and downloaded at http://cgss.ruc.edu.cn/English/Home.htm

Here's a basic template for cleaning data across different waves.

gen p=provinces

gen male=1 if a2==1
replace male=0 if a2==2

clonevar edu_raw=a7a

gen edu=1 if edu_raw>=1&edu_raw<=4
replace edu=2 if edu_raw>=5&edu_raw<=8
replace edu=3 if edu_raw>=9&edu_raw<=14

*birth year of respondent
gen byr=a31

gen age=year-byr if byr>=1900
gen age2=age^2

gen han=1 if a4==1
replace han=0 if a4>1&a4<9


*hukou
clonevar hukou_nong=a18

clonevar mari_raw=a69


*# of children have
gen son=a681 if a681>=0&a681<=30
gen daughter=a682 if a682>=0&a682<=30

gen children_have=son+daughter
replace children_have=son if daughter==0&children_have==.
replace children_have=daughter  if son==0&children_have==.

*self-assessed health
gen sah=a15 if a15>0&a15<=5

*public insurances
gen hinsurance=1 if a611==1
replace hinsurance=0 if a611==2

gen sinsurance=1 if a612==1
replace sinsurance=0 if a612==2

*commercial insurances
gen hinsurance_comm=1 if a613==1
replace hinsurance_comm=0 if a613==2

gen sinsurance_comm=1 if a614==1
replace sinsurance_comm=0 if a614==2


gen income_hh=a62



clear all

cap log close

use "cgss17.dta"

append using "cgss15.dta",force

append using "cgss13.dta",force

append using "cgss12.dta",force

append using "cgss10.dta",force

append using "cgss18.dta",force


save "cgss10-18.dta",replace

*/

clear all
cap log use

use "/Users/cici/Desktop/CiCi/Research/child and insurance/use cgss/cgss10-18.dta"

replace province="广东省" if province=="深圳市"
encode province, gen(pr)
gen temp=pr


drop if byr<0
drop if year==.


// cpi from world bank, 2010=100
// https://data.worldbank.org/indicator/FP.CPI.TOTL?locations=CN

gen cpi=100 if year==2010
replace cpi=108.318909 if year==2012
replace cpi=111.1580018 if year==2013
replace cpi=114.9221228 if year==2015
replace cpi=119.0880504 if year==2017
replace cpi=121.6 if year==2018
gen base=100 //2010

replace income_hh=. if income_hh>9999996

replace income_hh=income_hh*base/cpi

gen rinc_hh1=sign(income_hh) * ln1p(abs(income_hh))

*Define basic asic variable 
gen dink=1 if children_have==0
replace dink=0 if children_have>0&children_have<=20

gen mom=1 if male==0&dink==0
gen dad=1 if male==1&dink==0

gen parent=1 if mom==1|dad==1


tab children_have
drop if children_have>20&children_have<=32

gen ins=1 if sinsurance==1|hinsurance==1|sinsurance_c==1|hinsurance_c==1
replace ins=0 if sinsurance==0&hinsurance==0&sinsurance_c==0&hinsurance_c==0


gen ins_c=1 if sinsurance_c==1|hinsurance_c==1
replace ins_c=0 if sinsurance_c==0&hinsurance_c==0

gen ins_social=1 if sinsurance==1|hinsurance==1
replace ins_social=0 if sinsurance==0&hinsurance==0


**********************************************
**********Generate Policy Exposure index******
**********************************************

**this is the index following Chen&Fang (2021)

gen byr_spouse=a71a if a71a>1900&a71a<2000


*beijing
forvalue i=15(1)49{
	gen ca_`i'llp=byr+`i' if temp==4
	gen index_`i'llp=1 if ca_`i'llp>1973&temp==4
	replace index_`i'llp=0 if ca_`i'llp<=1973&temp==4
} 

forvalue i=15(1)19{
	gen AFR_jing`i'llp=0.017
}

forvalue i=20(1)24{
	gen AFR_jing`i'llp=0.172
}

forvalue i=25(1)29{
	gen AFR_jing`i'llp=0.269
}

forvalue i=30(1)34{
	gen AFR_jing`i'llp=0.123
}


forvalue i=35(1)39{
	gen AFR_jing`i'llp=0.082
}

forvalue i=40(1)44{
	gen AFR_jing`i'llp=0.043
}

forvalue i=45(1)49{
	gen AFR_jing`i'llp=0.000
}

forv i=15(1)49{
		gen ffp_`i'llp=AFR_jing`i'llp*index_`i'llp if temp==4
}





*tianjin
forvalue i=15(1)49{
	replace ca_`i'llp=byr+`i' if temp==7
	replace index_`i'llp=1 if ca_`i'llp>1972 &temp==7
	replace index_`i'llp=0 if ca_`i'llp<=1972&temp==7
} 


forvalue i=15(1)19{
	gen AFR_jin`i'llp=0.006
}

forvalue i=20(1)24{
	gen AFR_jin`i'llp=0.161
}

forvalue i=25(1)29{
	gen AFR_jin`i'llp=0.236
}

forvalue i=30(1)34{
	gen AFR_jin`i'llp=0.135
}


forvalue i=35(1)39{
	gen AFR_jin`i'llp=0.080
}

forvalue i=40(1)44{
	gen AFR_jin`i'llp=0.042
}

forvalue i=45(1)49{
	gen AFR_jin`i'llp=0.007
}


forv i=15(1)49{
		replace ffp_`i'llp=AFR_jin`i'llp*index_`i'llp if temp==7
}



*hebei
forvalue i=15(1)49{
	replace ca_`i'llp=byr+`i' if temp==17 
	replace index_`i'llp=1 if ca_`i'llp>1972 & temp==17
	replace index_`i'llp=0 if ca_`i'llp<=1972&temp==17
} 



forvalue i=15(1)19{
	gen AFR_ji`i'llp=0.028
}

forvalue i=20(1)24{
	gen AFR_ji`i'llp=0.239
}

forvalue i=25(1)29{
	gen AFR_ji`i'llp=0.304
}

forvalue i=30(1)34{
	gen AFR_ji`i'llp=0.263
}


forvalue i=35(1)39{
	gen AFR_ji`i'llp=0.171
}

forvalue i=40(1)44{
	gen AFR_ji`i'llp=0.068
}

forvalue i=45(1)49{
	gen AFR_ji`i'llp=0.009
}


forv i=15(1)49{
		replace ffp_`i'llp=AFR_ji`i'llp*index_`i'llp if temp==17
}



*Shanxi
forvalue i=15(1)49{
	replace ca_`i'llp=byr+`i' if temp==11 
	replace index_`i'llp=1 if ca_`i'llp>1971 & temp==11
	replace index_`i'llp=0 if ca_`i'llp<=1971&temp==11
} 


forvalue i=15(1)19{
	gen AFR_shan`i'llp=0.067
}

forvalue i=20(1)24{
	gen AFR_shan`i'llp=0.304
}

forvalue i=25(1)29{
	gen AFR_shan`i'llp=0.315
}

forvalue i=30(1)34{
	gen AFR_shan`i'llp=0.282
}


forvalue i=35(1)39{
	gen AFR_shan`i'llp=0.185
}

forvalue i=40(1)44{
	gen AFR_shan`i'llp=0.077
}

forvalue i=45(1)49{
	gen AFR_shan`i'llp=0.013
}


forv i=15(1)49{
		replace ffp_`i'llp=AFR_shan`i'llp*index_`i'llp if temp==11
}



*inner
forvalue i=15(1)49{
	replace ca_`i'llp=byr+`i' if temp==3 
	replace index_`i'llp=1 if ca_`i'llp>1972 & temp==3
	replace index_`i'llp=0 if ca_`i'llp<=1972&temp==3
} 


forvalue i=15(1)19{
	gen AFR_inner`i'llp=0.060
}

forvalue i=20(1)24{
	gen AFR_inner`i'llp=0.358
}

forvalue i=25(1)29{
	gen AFR_inner`i'llp=0.357
}

forvalue i=30(1)34{
	gen AFR_inner`i'llp=0.267
}


forvalue i=35(1)39{
	gen AFR_inner`i'llp=0.181
}

forvalue i=40(1)44{
	gen AFR_inner`i'llp=0.073
}

forvalue i=45(1)49{
	gen AFR_inner`i'llp=0.005
}


forv i=15(1)49{
		replace ffp_`i'llp=AFR_inner`i'llp*index_`i'llp if temp==3
}


*zhejiang
forvalue i=15(1)49{
	replace ca_`i'llp=byr+`i' if temp==19 
	replace index_`i'llp=1 if ca_`i'llp>1971 & temp==19
	replace index_`i'llp=0 if ca_`i'llp<=1971&temp==19
} 


forvalue i=15(1)19{
	gen AFR_zhe`i'llp=0.084
}

forvalue i=20(1)24{
	gen AFR_zhe`i'llp=0.333
}

forvalue i=25(1)29{
	gen AFR_zhe`i'llp=0.299
}

forvalue i=30(1)34{
	gen AFR_zhe`i'llp=0.191
}


forvalue i=35(1)39{
	gen AFR_zhe`i'llp=0.153
}

forvalue i=40(1)44{
	gen AFR_zhe`i'llp=0.072
}

forvalue i=45(1)49{
	gen AFR_zhe`i'llp=0.000
}


forv i=15(1)49{
		replace ffp_`i'llp=AFR_zhe`i'llp*index_`i'llp if temp==19
}



*jiangsu
forvalue i=15(1)49{
	replace ca_`i'llp=byr+`i' if temp==15 
	replace index_`i'llp=1 if ca_`i'llp>1973 & temp==15
	replace index_`i'llp=0 if ca_`i'llp<=1973&temp==15
} 


forvalue i=15(1)19{
	gen AFR_su`i'llp=0.022
}

forvalue i=20(1)24{
	gen AFR_su`i'llp=0.262
}

forvalue i=25(1)29{
	gen AFR_su`i'llp=0.321
}

forvalue i=30(1)34{
	gen AFR_su`i'llp=0.217
}


forvalue i=35(1)39{
	gen AFR_su`i'llp=0.133
}

forvalue i=40(1)44{
	gen AFR_su`i'llp=0.063
}

forvalue i=45(1)49{
	gen AFR_su`i'llp=0.009
}


forv i=15(1)49{
		replace ffp_`i'llp=AFR_su`i'llp*index_`i'llp if temp==15
}



*shanghai
forvalue i=15(1)49{
	replace ca_`i'llp=byr+`i' if temp==1 
	replace index_`i'llp=1 if ca_`i'llp>1973 & temp==1
	replace index_`i'llp=0 if ca_`i'llp<=1973&temp==1
} 


forvalue i=15(1)19{
	gen AFR_hu`i'llp=0.005
}

forvalue i=20(1)24{
	gen AFR_hu`i'llp=0.162
}

forvalue i=25(1)29{
	gen AFR_hu`i'llp=0.223
}

forvalue i=30(1)34{
	gen AFR_hu`i'llp=0.122
}


forvalue i=35(1)39{
	gen AFR_hu`i'llp=0.045
}

forvalue i=40(1)44{
	gen AFR_hu`i'llp=0.015
}

forvalue i=45(1)49{
	gen AFR_hu`i'llp=0.000
}


forv i=15(1)49{
		replace ffp_`i'llp=AFR_hu`i'llp*index_`i'llp if temp==1
}


*heilongjiang
forvalue i=15(1)49{
	replace ca_`i'llp=byr+`i' if temp==31 
	replace index_`i'llp=1 if ca_`i'llp>1972 & temp==31
	replace index_`i'llp=0 if ca_`i'llp<=1972&temp==31
} 


forvalue i=15(1)19{
	gen AFR_hei`i'llp=0.073
}

forvalue i=20(1)24{
	gen AFR_hei`i'llp=0.315
}

forvalue i=25(1)29{
	gen AFR_hei`i'llp=0.364
}

forvalue i=30(1)34{
	gen AFR_hei`i'llp=0.242
}


forvalue i=35(1)39{
	gen AFR_hei`i'llp=0.202
}

forvalue i=40(1)44{
	gen AFR_hei`i'llp=0.098
}

forvalue i=45(1)49{
	gen AFR_hei`i'llp=0.018
}


forv i=15(1)49{
		replace ffp_`i'llp=AFR_hei`i'llp*index_`i'llp if temp==31
}



*jilin
forvalue i=15(1)49{
	replace ca_`i'llp=byr+`i' if temp==5 
	replace index_`i'llp=1 if ca_`i'llp>1972 & temp==5
	replace index_`i'llp=0 if ca_`i'llp<=1972&temp==5
} 

forvalue i=15(1)19{
	gen AFR_jilin`i'llp=0.066
}

forvalue i=20(1)24{
	gen AFR_jilin`i'llp=0.288
}

forvalue i=25(1)29{
	gen AFR_jilin`i'llp=0.333
}

forvalue i=30(1)34{
	gen AFR_jilin`i'llp=0.292
}


forvalue i=35(1)39{
	gen AFR_jilin`i'llp=0.183
}

forvalue i=40(1)44{
	gen AFR_jilin`i'llp=0.118
}

forvalue i=45(1)49{
	gen AFR_jilin`i'llp=0.009
}


forv i=15(1)49{
		replace ffp_`i'llp=AFR_jilin`i'llp*index_`i'llp if temp==5
}


*liaoning
forvalue i=15(1)49{
	replace ca_`i'llp=byr+`i' if temp==27 
	replace index_`i'llp=1 if ca_`i'llp>1972 & temp==27
	replace index_`i'llp=0 if ca_`i'llp<=1972&temp==27
} 


forvalue i=15(1)19{
	gen AFR_liao`i'llp=0.022
}

forvalue i=20(1)24{
	gen AFR_liao`i'llp=0.240
}

forvalue i=25(1)29{
	gen AFR_liao`i'llp=0.330
}

forvalue i=30(1)34{
	gen AFR_liao`i'llp=0.231
}


forvalue i=35(1)39{
	gen AFR_liao`i'llp=0.154
}

forvalue i=40(1)44{
	gen AFR_liao`i'llp=0.078
}

forvalue i=45(1)49{
	gen AFR_liao`i'llp=0.006
}


forv i=15(1)49{
		replace ffp_`i'llp=AFR_liao`i'llp*index_`i'llp if temp==27
}



*anhui
forvalue i=15(1)49{
	replace ca_`i'llp=byr+`i' if temp==9 
	replace index_`i'llp=1 if ca_`i'llp>1972 & temp==9
	replace index_`i'llp=0 if ca_`i'llp<=1972&temp==9
} 


forvalue i=15(1)19{
	gen AFR_wan`i'llp=0.051
}

forvalue i=20(1)24{
	gen AFR_wan`i'llp=0.343
}

forvalue i=25(1)29{
	gen AFR_wan`i'llp=0.364
}

forvalue i=30(1)34{
	gen AFR_wan`i'llp=0.327
}


forvalue i=35(1)39{
	gen AFR_wan`i'llp=0.237
}

forvalue i=40(1)44{
	gen AFR_wan`i'llp=0.098
}

forvalue i=45(1)49{
	gen AFR_wan`i'llp=0.015
}


forv i=15(1)49{
		replace ffp_`i'llp=AFR_wan`i'llp*index_`i'llp if temp==9
}




*fujian
forvalue i=15(1)49{
	replace ca_`i'llp=byr+`i' if temp==24 
	replace index_`i'llp=1 if ca_`i'llp>1972 & temp==24
	replace index_`i'llp=0 if ca_`i'llp<=1972&temp==24
} 


forvalue i=15(1)19{
	gen AFR_min`i'llp=0.068
}

forvalue i=20(1)24{
	gen AFR_min`i'llp=0.355
}

forvalue i=25(1)29{
	gen AFR_min`i'llp=0.349
}

forvalue i=30(1)34{
	gen AFR_min`i'llp=0.297
}


forvalue i=35(1)39{
	gen AFR_min`i'llp=0.186
}

forvalue i=40(1)44{
	gen AFR_min`i'llp=0.115
}

forvalue i=45(1)49{
	gen AFR_min`i'llp=0.000
}


forv i=15(1)49{
		replace ffp_`i'llp=AFR_min`i'llp*index_`i'llp if temp==24
}



*jiangxi
forvalue i=15(1)49{
	replace ca_`i'llp=byr+`i' if temp==16 
	replace index_`i'llp=1 if ca_`i'llp>1972 & temp==16
	replace index_`i'llp=0 if ca_`i'llp<=1972&temp==16
} 


forvalue i=15(1)19{
	gen AFR_gan`i'llp=0.107
}

forvalue i=20(1)24{
	gen AFR_gan`i'llp=0.358
}

forvalue i=25(1)29{
	gen AFR_gan`i'llp=0.373
}

forvalue i=30(1)34{
	gen AFR_gan`i'llp=0.303
}


forvalue i=35(1)39{
	gen AFR_gan`i'llp=0.248
}

forvalue i=40(1)44{
	gen AFR_gan`i'llp=0.114
}

forvalue i=45(1)49{
	gen AFR_gan`i'llp=0.012
}


forv i=15(1)49{
		replace ffp_`i'llp=AFR_gan`i'llp*index_`i'llp if temp==16
}




*shandong
forvalue i=15(1)49{
	replace ca_`i'llp=byr+`i' if temp==10 
	replace index_`i'llp=1 if ca_`i'llp>1970 & temp==10
	replace index_`i'llp=0 if ca_`i'llp<=1970&temp==10
} 


forvalue i=15(1)19{
	gen AFR_lu`i'llp=0.016
}

forvalue i=20(1)24{
	gen AFR_lu`i'llp=0.263
}

forvalue i=25(1)29{
	gen AFR_lu`i'llp=0.327
}

forvalue i=30(1)34{
	gen AFR_lu`i'llp=0.246
}


forvalue i=35(1)39{
	gen AFR_lu`i'llp=0.153
}

forvalue i=40(1)44{
	gen AFR_lu`i'llp=0.057
}

forvalue i=45(1)49{
	gen AFR_lu`i'llp=0.008
}


forv i=15(1)49{
		replace ffp_`i'llp=AFR_lu`i'llp*index_`i'llp if temp==10
}



*henan
forvalue i=15(1)49{
	replace ca_`i'llp=byr+`i' if temp==18 
	replace index_`i'llp=1 if ca_`i'llp>1973 & temp==18
	replace index_`i'llp=0 if ca_`i'llp<=1973&temp==18
} 



forvalue i=15(1)19{
	gen AFR_henan`i'llp=0.024
}

forvalue i=20(1)24{
	gen AFR_henan`i'llp=0.317
}

forvalue i=25(1)29{
	gen AFR_henan`i'llp=0.362
}

forvalue i=30(1)34{
	gen AFR_henan`i'llp=0.304
}


forvalue i=35(1)39{
	gen AFR_henan`i'llp=0.255
}

forvalue i=40(1)44{
	gen AFR_henan`i'llp=0.135
}

forvalue i=45(1)49{
	gen AFR_henan`i'llp=0.008
}


forv i=15(1)49{
		replace ffp_`i'llp=AFR_henan`i'llp*index_`i'llp if temp==18
}





*hubei
forvalue i=15(1)49{
	replace ca_`i'llp=byr+`i' if temp==21
	replace index_`i'llp=1 if ca_`i'llp>1971 & temp==21
	replace index_`i'llp=0 if ca_`i'llp<=1971&temp==21
} 


forvalue i=15(1)19{
	gen AFR_e`i'llp=0.046
}

forvalue i=20(1)24{
	gen AFR_e`i'llp=0.345
}

forvalue i=25(1)29{
	gen AFR_e`i'llp=0.395
}

forvalue i=30(1)34{
	gen AFR_e`i'llp=0.328
}


forvalue i=35(1)39{
	gen AFR_e`i'llp=0.219
}

forvalue i=40(1)44{
	gen AFR_e`i'llp=0.114
}

forvalue i=45(1)49{
	gen AFR_e`i'llp=0.005
}

forv i=15(1)49{
		replace ffp_`i'llp=AFR_e`i'llp*index_`i'llp if temp==21
}




*hunan
forvalue i=15(1)49{
	replace ca_`i'llp=byr+`i' if temp==22 
	replace index_`i'llp=1 if ca_`i'llp>1971 & temp==22
	replace index_`i'llp=0 if ca_`i'llp<=1971&temp==22
} 


forvalue i=15(1)19{
	gen AFR_xiang`i'llp=0.056
}

forvalue i=20(1)24{
	gen AFR_xiang`i'llp=0.395
}

forvalue i=25(1)29{
	gen AFR_xiang`i'llp=0.407
}

forvalue i=30(1)34{
	gen AFR_xiang`i'llp=0.324
}


forvalue i=35(1)39{
	gen AFR_xiang`i'llp=0.227
}

forvalue i=40(1)44{
	gen AFR_xiang`i'llp=0.110
}

forvalue i=45(1)49{
	gen AFR_xiang`i'llp=0.019
}


forv i=15(1)49{
		replace ffp_`i'llp=AFR_xiang`i'llp*index_`i'llp if temp==22
}




*guangdong
forvalue i=15(1)49{
	replace ca_`i'llp=byr+`i' if temp==12 
	replace index_`i'llp=1 if ca_`i'llp>1969 & temp==12
	replace index_`i'llp=0 if ca_`i'llp<=1969&temp==12
} 


forvalue i=15(1)19{
	gen AFR_yue`i'llp=0.027
}

forvalue i=20(1)24{
	gen AFR_yue`i'llp=0.245
}

forvalue i=25(1)29{
	gen AFR_yue`i'llp=0.319
}

forvalue i=30(1)34{
	gen AFR_yue`i'llp=0.306
}


forvalue i=35(1)39{
	gen AFR_yue`i'llp=0.205
}

forvalue i=40(1)44{
	gen AFR_yue`i'llp=0.085
}

forvalue i=45(1)49{
	gen AFR_yue`i'llp=0.012
}


forv i=15(1)49{
		replace ffp_`i'llp=AFR_yue`i'llp*index_`i'llp if temp==12
}



*guangxi
forvalue i=15(1)49{
	replace ca_`i'llp=byr+`i' if temp==13 
	replace index_`i'llp=1 if ca_`i'llp>1974 & temp==13
	replace index_`i'llp=0 if ca_`i'llp<=1974&temp==13
} 


forvalue i=15(1)19{
	gen AFR_gui`i'llp=0.038
}

forvalue i=20(1)24{
	gen AFR_gui`i'llp=0.281
}

forvalue i=25(1)29{
	gen AFR_gui`i'llp=0.364
}

forvalue i=30(1)34{
	gen AFR_gui`i'llp=0.298
}


forvalue i=35(1)39{
	gen AFR_gui`i'llp=0.249
}

forvalue i=40(1)44{
	gen AFR_gui`i'llp=0.125
}

forvalue i=45(1)49{
	gen AFR_gui`i'llp=0.022
}


forv i=15(1)49{
		replace ffp_`i'llp=AFR_gui`i'llp*index_`i'llp if temp==13
}



*sichuan
forvalue i=15(1)49{
	replace ca_`i'llp=byr+`i' if temp==6 
	replace index_`i'llp=1 if ca_`i'llp>1971 & temp==6
	replace index_`i'llp=0 if ca_`i'llp<=1971&temp==6
} 


forvalue i=15(1)19{
	gen AFR_chuan`i'llp=0.039
}

forvalue i=20(1)24{
	gen AFR_chuan`i'llp=0.319
}

forvalue i=25(1)29{
	gen AFR_chuan`i'llp=0.357
}

forvalue i=30(1)34{
	gen AFR_chuan`i'llp=0.285
}


forvalue i=35(1)39{
	gen AFR_chuan`i'llp=0.230
}

forvalue i=40(1)44{
	gen AFR_chuan`i'llp=0.117
}

forvalue i=45(1)49{
	gen AFR_chuan`i'llp=0.018
}


forv i=15(1)49{
		replace ffp_`i'llp=AFR_chuan`i'llp*index_`i'llp if temp==6
}



*guizhou
forvalue i=15(1)49{
	replace ca_`i'llp=byr+`i' if temp==26 
	replace index_`i'llp=1 if ca_`i'llp>1975 & temp==26
	replace index_`i'llp=0 if ca_`i'llp<=1975&temp==26
} 


forvalue i=15(1)19{
	gen AFR_qian`i'llp=0.061
}

forvalue i=20(1)24{
	gen AFR_qian`i'llp=0.297
}

forvalue i=25(1)29{
	gen AFR_qian`i'llp=0.414
}

forvalue i=30(1)34{
	gen AFR_qian`i'llp=0.368
}


forvalue i=35(1)39{
	gen AFR_qian`i'llp=0.284
}

forvalue i=40(1)44{
	gen AFR_qian`i'llp=0.168
}

forvalue i=45(1)49{
	gen AFR_qian`i'llp=0.017
}


forv i=15(1)49{
		replace ffp_`i'llp=AFR_qian`i'llp*index_`i'llp if temp==26
}




*yunnan
forvalue i=15(1)49{
	replace ca_`i'llp=byr+`i' if temp==2
	replace index_`i'llp=1 if ca_`i'llp>1972 & temp==2
	replace index_`i'llp=0 if ca_`i'llp<=1972&temp==2
} 


forvalue i=15(1)19{
	gen AFR_dian`i'llp=0.056
}

forvalue i=20(1)24{
	gen AFR_dian`i'llp=0.313
}

forvalue i=25(1)29{
	gen AFR_dian`i'llp=0.315
}

forvalue i=30(1)34{
	gen AFR_dian`i'llp=0.310
}


forvalue i=35(1)39{
	gen AFR_dian`i'llp=0.204
}

forvalue i=40(1)44{
	gen AFR_dian`i'llp=0.133
}

forvalue i=45(1)49{
	gen AFR_dian`i'llp=0.011
}


forv i=15(1)49{
		replace ffp_`i'llp=AFR_dian`i'llp*index_`i'llp if temp==2
}



*shaanxi
forvalue i=15(1)49{
	replace ca_`i'llp=byr+`i' if temp==29 
	replace index_`i'llp=1 if ca_`i'llp>1971 & temp==29
	replace index_`i'llp=0 if ca_`i'llp<=1971&temp==29
} 



forvalue i=15(1)19{
	gen AFR_shaan`i'llp=0.069
}

forvalue i=20(1)24{
	gen AFR_shaan`i'llp=0.304
}

forvalue i=25(1)29{
	gen AFR_shaan`i'llp=0.356
}

forvalue i=30(1)34{
	gen AFR_shaan`i'llp=0.255
}


forvalue i=35(1)39{
	gen AFR_shaan`i'llp=0.170
}

forvalue i=40(1)44{
	gen AFR_shaan`i'llp=0.100
}

forvalue i=45(1)49{
	gen AFR_shaan`i'llp=0.011
}


forv i=15(1)49{
		replace ffp_`i'llp=AFR_shaan`i'llp*index_`i'llp if temp==29
}





*gansu
forvalue i=15(1)49{
	replace ca_`i'llp=byr+`i' if temp==23 
	replace index_`i'llp=1 if ca_`i'llp>1971 & temp==23
	replace index_`i'llp=0 if ca_`i'llp<=1971&temp==23
} 


forvalue i=15(1)19{
	gen AFR_gansu`i'llp=0.118
}

forvalue i=20(1)24{
	gen AFR_gansu`i'llp=0.343
}

forvalue i=25(1)29{
	gen AFR_gansu`i'llp=0.347
}

forvalue i=30(1)34{
	gen AFR_gansu`i'llp=0.313
}


forvalue i=35(1)39{
	gen AFR_gansu`i'llp=0.200
}

forvalue i=40(1)44{
	gen AFR_gansu`i'llp=0.131
}

forvalue i=45(1)49{
	gen AFR_gansu`i'llp=0.037
}


forv i=15(1)49{
		replace ffp_`i'llp=AFR_gansu`i'llp*index_`i'llp if temp==23
}



*qinghai
forvalue i=15(1)49{
	replace ca_`i'llp=byr+`i' if temp==30 
	replace index_`i'llp=1 if ca_`i'llp>1973 & temp==30
	replace index_`i'llp=0 if ca_`i'llp<=1973&temp==30
} 


forvalue i=15(1)19{
	gen AFR_qinghai`i'llp=0.138
}

forvalue i=20(1)24{
	gen AFR_qinghai`i'llp=0.292
}

forvalue i=25(1)29{
	gen AFR_qinghai`i'llp=0.287
}

forvalue i=30(1)34{
	gen AFR_qinghai`i'llp=0.287
}


forvalue i=35(1)39{
	gen AFR_qinghai`i'llp=0.212
}

forvalue i=40(1)44{
	gen AFR_qinghai`i'llp=0.149
}

forvalue i=45(1)49{
	gen AFR_qinghai`i'llp=0.051
}


forv i=15(1)49{
		replace ffp_`i'llp=AFR_qinghai`i'llp*index_`i'llp if temp==30
}



*ningxia
forvalue i=15(1)49{
	replace ca_`i'llp=byr+`i' if temp==8 
	replace index_`i'llp=1 if ca_`i'llp>1972 & temp==8
	replace index_`i'llp=0 if ca_`i'llp<=1972&temp==8
} 


forvalue i=15(1)19{
	gen AFR_ning`i'llp=0.087
}

forvalue i=20(1)24{
	gen AFR_ning`i'llp=0.417
}

forvalue i=25(1)29{
	gen AFR_ning`i'llp=0.367
}

forvalue i=30(1)34{
	gen AFR_ning`i'llp=0.256
}


forvalue i=35(1)39{
	gen AFR_ning`i'llp=0.219
}

forvalue i=40(1)44{
	gen AFR_ning`i'llp=0.070
}

forvalue i=45(1)49{
	gen AFR_ning`i'llp=0.086
}


forv i=15(1)49{
		replace ffp_`i'llp=AFR_ning`i'llp*index_`i'llp if temp==8
}



egen ffp_llp=rowtotal(ffp_15llp ffp_16llp ffp_17llp ffp_18llp ffp_19llp ffp_20llp ffp_21llp ffp_22llp ffp_23llp ffp_24llp ffp_25llp ffp_26llp ffp_27llp ffp_28llp ffp_29llp ffp_30llp ffp_31llp ffp_32llp ffp_33llp ffp_34llp ffp_35llp ffp_36llp ffp_37llp ffp_38llp ffp_39llp ffp_40llp ffp_41llp ffp_42llp ffp_43llp ffp_44llp ffp_45llp ffp_46llp ffp_47llp ffp_48llp ffp_49llp)

replace ffp_llp=. if temp==14 /*xinjiang*/
replace ffp_llp=. if temp==20/*hainan*/
replace ffp_llp=. if temp==25 /*xizang*/
replace ffp_llp=. if temp==28/*chongqing*/



*spouse exposure index
forvalue i=15(1)49{
	gen ca_`i'llps=byr_spouse+`i' if temp==1 
	gen index_`i'llps=1 if ca_`i'llps>1973 & temp==1
	replace index_`i'llps=0 if ca_`i'llps<=1973&temp==1
} 


forvalue i=15(1)49{
	replace ca_`i'llps=byr_spouse+`i' if temp==2
	replace index_`i'llps=1 if ca_`i'llps>1972 & temp==2
	replace index_`i'llps=0 if ca_`i'llps<=1972&temp==2
} 

forvalue i=15(1)49{
	replace ca_`i'llps=byr_spouse+`i' if temp==3 
	replace index_`i'llps=1 if ca_`i'llps>1972 & temp==3
	replace index_`i'llps=0 if ca_`i'llps<=1972&temp==3
} 


forvalue i=15(1)49{
	replace ca_`i'llps=byr_spouse+`i' if temp==4
	replace index_`i'llps=1 if ca_`i'llps>1973&temp==4
	replace index_`i'llps=0 if ca_`i'llps<=1973&temp==4
} 

forvalue i=15(1)49{
	replace ca_`i'llps=byr_spouse+`i' if temp==5 
	replace index_`i'llps=1 if ca_`i'llps>1972 & temp==5
	replace index_`i'llps=0 if ca_`i'llps<=1972&temp==5
} 


forvalue i=15(1)49{
	replace ca_`i'llps=byr_spouse+`i' if temp==6 
	replace index_`i'llps=1 if ca_`i'llps>1971 & temp==6
	replace index_`i'llps=0 if ca_`i'llps<=1971&temp==6
} 


forvalue i=15(1)49{
	replace ca_`i'llps=byr_spouse+`i' if temp==7
	replace index_`i'llps=1 if ca_`i'llps>1972 &temp==7
	replace index_`i'llps=0 if ca_`i'llps<=1972&temp==7
} 


forvalue i=15(1)49{
	replace ca_`i'llps=byr_spouse+`i' if temp==8 
	replace index_`i'llps=1 if ca_`i'llps>1972 & temp==8
	replace index_`i'llps=0 if ca_`i'llps<=1972&temp==8
} 


forvalue i=15(1)49{
	replace ca_`i'llps=byr_spouse+`i' if temp==9 
	replace index_`i'llps=1 if ca_`i'llps>1972 & temp==9
	replace index_`i'llps=0 if ca_`i'llps<=1972&temp==9
} 


forvalue i=15(1)49{
	replace ca_`i'llps=byr_spouse+`i' if temp==10 
	replace index_`i'llps=1 if ca_`i'llps>1970 & temp==10
	replace index_`i'llps=0 if ca_`i'llps<=1970&temp==10
} 


forvalue i=15(1)49{
	replace ca_`i'llps=byr_spouse+`i' if temp==11 
	replace index_`i'llps=1 if ca_`i'llps>1971 & temp==11
	replace index_`i'llps=0 if ca_`i'llps<=1971&temp==11
} 



forvalue i=15(1)49{
	replace ca_`i'llps=byr_spouse+`i' if temp==12 
	replace index_`i'llps=1 if ca_`i'llps>1969 & temp==12
	replace index_`i'llps=0 if ca_`i'llps<=1969&temp==12
} 



forvalue i=15(1)49{
	replace ca_`i'llps=byr_spouse+`i' if temp==13 
	replace index_`i'llps=1 if ca_`i'llps>1974 & temp==13
	replace index_`i'llps=0 if ca_`i'llps<=1974&temp==13
} 


forvalue i=15(1)49{
	replace ca_`i'llps=byr_spouse+`i' if temp==15 
	replace index_`i'llps=1 if ca_`i'llps>1973 & temp==15
	replace index_`i'llps=0 if ca_`i'llps<=1973&temp==15
} 


forvalue i=15(1)49{
	replace ca_`i'llps=byr_spouse+`i' if temp==16 
	replace index_`i'llps=1 if ca_`i'llps>1972 & temp==16
	replace index_`i'llps=0 if ca_`i'llps<=1972&temp==16
} 



forvalue i=15(1)49{
	replace ca_`i'llps=byr_spouse+`i' if temp==17 
	replace index_`i'llps=1 if ca_`i'llps>1972 & temp==17
	replace index_`i'llps=0 if ca_`i'llps<=1972&temp==17
} 


forvalue i=15(1)49{
	replace ca_`i'llps=byr_spouse+`i' if temp==18 
	replace index_`i'llps=1 if ca_`i'llps>1973 & temp==18
	replace index_`i'llps=0 if ca_`i'llps<=1973&temp==18
} 


forvalue i=15(1)49{
	replace ca_`i'llps=byr_spouse+`i' if temp==19 
	replace index_`i'llps=1 if ca_`i'llps>1971 & temp==19
	replace index_`i'llps=0 if ca_`i'llps<=1971&temp==19
} 


forvalue i=15(1)49{
	replace ca_`i'llps=byr_spouse+`i' if temp==21
	replace index_`i'llps=1 if ca_`i'llps>1971 & temp==21
	replace index_`i'llps=0 if ca_`i'llps<=1971&temp==21
} 



forvalue i=15(1)49{
	replace ca_`i'llps=byr_spouse+`i' if temp==22 
	replace index_`i'llps=1 if ca_`i'llps>1971 & temp==22
	replace index_`i'llps=0 if ca_`i'llps<=1971&temp==22
} 


forvalue i=15(1)49{
	replace ca_`i'llps=byr_spouse+`i' if temp==23 
	replace index_`i'llps=1 if ca_`i'llps>1971 & temp==23
	replace index_`i'llps=0 if ca_`i'llps<=1971&temp==23
} 

forvalue i=15(1)49{
	replace ca_`i'llps=byr_spouse+`i' if temp==24 
	replace index_`i'llps=1 if ca_`i'llps>1972 & temp==24
	replace index_`i'llps=0 if ca_`i'llps<=1972&temp==24
} 


forvalue i=15(1)49{
	replace ca_`i'llps=byr_spouse+`i' if temp==26 
	replace index_`i'llps=1 if ca_`i'llps>1975 & temp==26
	replace index_`i'llps=0 if ca_`i'llps<=1975&temp==26
} 


forvalue i=15(1)49{
	replace ca_`i'llps=byr_spouse+`i' if temp==27 
	replace index_`i'llps=1 if ca_`i'llps>1972 & temp==27
	replace index_`i'llps=0 if ca_`i'llps<=1972&temp==27
} 



forvalue i=15(1)49{
	replace ca_`i'llps=byr_spouse+`i' if temp==29 
	replace index_`i'llps=1 if ca_`i'llps>1971 & temp==29
	replace index_`i'llps=0 if ca_`i'llps<=1971&temp==29
} 


forvalue i=15(1)49{
	replace ca_`i'llps=byr_spouse+`i' if temp==30 
	replace index_`i'llps=1 if ca_`i'llps>1973 & temp==30
	replace index_`i'llps=0 if ca_`i'llps<=1973&temp==30
} 


forvalue i=15(1)49{
	replace ca_`i'llps=byr_spouse+`i' if temp==31 
	replace index_`i'llps=1 if ca_`i'llps>1972 & temp==31
	replace index_`i'llps=0 if ca_`i'llps<=1972&temp==31
} 

*******************
forv i=15(1)49{
		gen ffp_`i'_spousellp=AFR_hu`i'llp*index_`i'llps if temp==1
}


forv i=15(1)49{
		replace ffp_`i'_spousellp=AFR_dian`i'llp*index_`i'llps if temp==2
}

forv i=15(1)49{
		replace ffp_`i'_spousellp=AFR_inner`i'llp*index_`i'llps if temp==3
}


forv i=15(1)49{
		replace ffp_`i'_spousellp=AFR_jing`i'llp*index_`i'llps if temp==4
}

forv i=15(1)49{
		replace ffp_`i'_spousellp=AFR_jilin`i'llp*index_`i'llps if temp==5
}


forv i=15(1)49{
		replace ffp_`i'_spousellp=AFR_chuan`i'llp*index_`i'llps if temp==6
}



forv i=15(1)49{
		replace ffp_`i'_spousellp=AFR_jin`i'llp*index_`i'llps if temp==7
}


forv i=15(1)49{
		replace ffp_`i'_spousellp=AFR_ning`i'llp*index_`i'llps if temp==8
}


forv i=15(1)49{
		replace ffp_`i'_spousellp=AFR_wan`i'llp*index_`i'llps if temp==9
}


forv i=15(1)49{
		replace ffp_`i'_spousellp=AFR_lu`i'llp*index_`i'llps if temp==10
}



forv i=15(1)49{
		replace ffp_`i'_spousellp=AFR_shaan`i'llp*index_`i'llps if temp==29
}

forv i=15(1)49{
		replace ffp_`i'_spousellp=AFR_yue`i'llp*index_`i'llps if temp==12
}



forv i=15(1)49{
		replace ffp_`i'_spousellp=AFR_gui`i'llp*index_`i'llps if temp==13
}



forv i=15(1)49{
		replace ffp_`i'_spousellp=AFR_su`i'llp*index_`i'llps if temp==15
}


forv i=15(1)49{
		replace ffp_`i'_spousellp=AFR_gan`i'llp*index_`i'llps if temp==16
}

forv i=15(1)49{
		replace ffp_`i'_spousellp=AFR_ji`i'llp*index_`i'llps if temp==17
}


forv i=15(1)49{
		replace ffp_`i'_spousellp=AFR_henan`i'llp*index_`i'llps if temp==18
}


forv i=15(1)49{
		replace ffp_`i'_spousellp=AFR_zhe`i'llp*index_`i'llps if temp==19
}


forv i=15(1)49{
		replace ffp_`i'_spousellp=AFR_e`i'llp*index_`i'llps if temp==21
}

forv i=15(1)49{
		replace ffp_`i'_spousellp=AFR_xiang`i'llp*index_`i'llps if temp==22
}


forv i=15(1)49{
		replace ffp_`i'_spousellp=AFR_gansu`i'llp*index_`i'llps if temp==23
}

forv i=15(1)49{
		replace ffp_`i'_spousellp=AFR_min`i'llp*index_`i'llps if temp==24
}


forv i=15(1)49{
		replace ffp_`i'_spousellp=AFR_qian`i'llp*index_`i'llps if temp==26
}


forv i=15(1)49{
		replace ffp_`i'_spousellp=AFR_liao`i'llp*index_`i'llps if temp==27
}


forv i=15(1)49{
		replace ffp_`i'_spousellp=AFR_shan`i'llp*index_`i'llps if temp==11
}


forv i=15(1)49{
		replace ffp_`i'_spousellp=AFR_qinghai`i'llp*index_`i'llps if temp==30
}



forv i=15(1)49{
		replace ffp_`i'_spousellp=AFR_hei`i'llp*index_`i'llps if temp==31
}



egen ffp_spousellp=rowtotal(ffp_15_spousellp ffp_16_spousellp ffp_17_spousellp ffp_18_spousellp ffp_19_spousellp ffp_20_spousellp ffp_21_spousellp ffp_22_spousellp ffp_23_spousellp ffp_24_spousellp ffp_25_spousellp ffp_26_spousellp ffp_27_spousellp ffp_28_spousellp ffp_29_spousellp ffp_30_spousellp ffp_31_spousellp ffp_32_spousellp ffp_33_spousellp ffp_34_spousellp ffp_35_spousellp ffp_36_spousellp ffp_37_spousellp ffp_38_spousellp ffp_39_spousellp ffp_40_spousellp ffp_41_spousellp ffp_42_spousellp ffp_43_spousellp ffp_44_spousellp ffp_45_spousellp ffp_46_spousellp ffp_47_spousellp ffp_48_spousellp ffp_49_spousellp)


replace ffp_spousellp=. if temp==14 /*xinjiang*/
replace ffp_spousellp=. if temp==20/*hainan*/
replace ffp_spousellp=. if temp==25 /*xizang*/
replace ffp_spousellp=. if temp==28/*chongqing*/


*******index as Chen, but using 1968 as pre policy fertility rate
gen ffp_llpwife=ffp_llp if male==0
replace ffp_llpwife=ffp_spousellp if male==1







*************************************************
****use the change before and after the reform*** this is the PEI used in main analysis
*************************************************

***1982-1968
*beijing 1982
forvalue i=15(1)19{
	gen AFR_jing`i'82=0.000
}

forvalue i=20(1)24{
	gen AFR_jing`i'82=0.079
}

forvalue i=25(1)29{
	gen AFR_jing`i'82=0.172
}

forvalue i=30(1)34{
	gen AFR_jing`i'82=0.033
}


forvalue i=35(1)39{
	gen AFR_jing`i'82=0.000
}

forvalue i=40(1)44{
	gen AFR_jing`i'82=0.000
}

forvalue i=45(1)49{
	gen AFR_jing`i'82=0.000
}



*tianjin 1982
forvalue i=15(1)19{
	gen AFR_jin`i'82=0.000
}

forvalue i=20(1)24{
	gen AFR_jin`i'82=0.051
}

forvalue i=25(1)29{
	gen AFR_jin`i'82=0.169
}

forvalue i=30(1)34{
	gen AFR_jin`i'82=0.039
}


forvalue i=35(1)39{
	gen AFR_jin`i'82=0.000
}

forvalue i=40(1)44{
	gen AFR_jin`i'82=0.010
}

forvalue i=45(1)49{
	gen AFR_jin`i'82=0.000
}



*hebei 1982
forvalue i=15(1)19{
	gen AFR_ji`i'82=0.009
}

forvalue i=20(1)24{
	gen AFR_ji`i'82=0.151
}

forvalue i=25(1)29{
	gen AFR_ji`i'82=0.2225
}

forvalue i=30(1)34{
	gen AFR_ji`i'82=0.101
}


forvalue i=35(1)39{
	gen AFR_ji`i'82=0.030
}

forvalue i=40(1)44{
	gen AFR_ji`i'82=0.016
}

forvalue i=45(1)49{
	gen AFR_ji`i'82=0.000
}



*Shanxi 1982
forvalue i=15(1)19{
	gen AFR_shan`i'82=0.026
}

forvalue i=20(1)24{
	gen AFR_shan`i'82=0.224
}

forvalue i=25(1)29{
	gen AFR_shan`i'82=0.210
}

forvalue i=30(1)34{
	gen AFR_shan`i'82=0.089
}


forvalue i=35(1)39{
	gen AFR_shan`i'82=0.010
}

forvalue i=40(1)44{
	gen AFR_shan`i'82=0.004
}

forvalue i=45(1)49{
	gen AFR_shan`i'82=0.000
}




*inner 1982
forvalue i=15(1)19{
	gen AFR_inner`i'82=0.022
}

forvalue i=20(1)24{
	gen AFR_inner`i'82=0.197
}

forvalue i=25(1)29{
	gen AFR_inner`i'82=0.273
}

forvalue i=30(1)34{
	gen AFR_inner`i'82=0.121
}


forvalue i=35(1)39{
	gen AFR_inner`i'82=0.023
}

forvalue i=40(1)44{
	gen AFR_inner`i'82=0.004
}

forvalue i=45(1)49{
	gen AFR_inner`i'82=0.000
}



*zhejiang 1982
forvalue i=15(1)19{
	gen AFR_zhe`i'82=0.017
}

forvalue i=20(1)24{
	gen AFR_zhe`i'82=0.220
}

forvalue i=25(1)29{
	gen AFR_zhe`i'82=0.159
}

forvalue i=30(1)34{
	gen AFR_zhe`i'82=0.031
}


forvalue i=35(1)39{
	gen AFR_zhe`i'82=0.015
}

forvalue i=40(1)44{
	gen AFR_zhe`i'82=0.003
}

forvalue i=45(1)49{
	gen AFR_zhe`i'82=0.005
}



*jiangsu 1982
forvalue i=15(1)19{
	gen AFR_su`i'82=0.010
}

forvalue i=20(1)24{
	gen AFR_su`i'82=0.158
}

forvalue i=25(1)29{
	gen AFR_su`i'82=0.166
}

forvalue i=30(1)34{
	gen AFR_su`i'82=0.031
}


forvalue i=35(1)39{
	gen AFR_su`i'82=0.006
}

forvalue i=40(1)44{
	gen AFR_su`i'82=0.001
}

forvalue i=45(1)49{
	gen AFR_su`i'82=0.003
}



*shanghai 1982
forvalue i=15(1)19{
	gen AFR_hu`i'82=0.005
}

forvalue i=20(1)24{
	gen AFR_hu`i'82=0.071
}

forvalue i=25(1)29{
	gen AFR_hu`i'82=0.142
}

forvalue i=30(1)34{
	gen AFR_hu`i'82=0.039
}


forvalue i=35(1)39{
	gen AFR_hu`i'82=0.010
}

forvalue i=40(1)44{
	gen AFR_hu`i'82=0.000
}

forvalue i=45(1)49{
	gen AFR_hu`i'82=0.000
}




*heilongjiang 1982

forvalue i=15(1)19{
	gen AFR_hei`i'82=0.026
}

forvalue i=20(1)24{
	gen AFR_hei`i'82=0.238
}

forvalue i=25(1)29{
	gen AFR_hei`i'82=0.203
}

forvalue i=30(1)34{
	gen AFR_hei`i'82=0.052
}


forvalue i=35(1)39{
	gen AFR_hei`i'82=0.005
}

forvalue i=40(1)44{
	gen AFR_hei`i'82=0.009
}

forvalue i=45(1)49{
	gen AFR_hei`i'82=0.000
}



*jilin
forvalue i=15(1)19{
	gen AFR_jilin`i'82=0.008
}

forvalue i=20(1)24{
	gen AFR_jilin`i'82=0.186
}

forvalue i=25(1)29{
	gen AFR_jilin`i'82=0.162
}

forvalue i=30(1)34{
	gen AFR_jilin`i'82=0.022
}


forvalue i=35(1)39{
	gen AFR_jilin`i'82=0.007
}

forvalue i=40(1)44{
	gen AFR_jilin`i'82=0.004
}

forvalue i=45(1)49{
	gen AFR_jilin`i'82=0.000
}



*liaoning 1982
forvalue i=15(1)19{
	gen AFR_liao`i'82=0.007
}

forvalue i=20(1)24{
	gen AFR_liao`i'82=0.172
}

forvalue i=25(1)29{
	gen AFR_liao`i'82=0.201
}

forvalue i=30(1)34{
	gen AFR_liao`i'82=0.017
}


forvalue i=35(1)39{
	gen AFR_liao`i'82=0.008
}

forvalue i=40(1)44{
	gen AFR_liao`i'82=0.005
}

forvalue i=45(1)49{
	gen AFR_liao`i'82=0.000
}



*anhui 1982
forvalue i=15(1)19{
	gen AFR_wan`i'82=0.031
}

forvalue i=20(1)24{
	gen AFR_wan`i'82=0.137
}

forvalue i=25(1)29{
	gen AFR_wan`i'82=0.208
}

forvalue i=30(1)34{
	gen AFR_wan`i'82=0.067
}


forvalue i=35(1)39{
	gen AFR_wan`i'82=0.016
}

forvalue i=40(1)44{
	gen AFR_wan`i'82=0.015
}

forvalue i=45(1)49{
	gen AFR_wan`i'82=0.002
}




*fujian 1982
forvalue i=15(1)19{
	gen AFR_min`i'82=0.023
}

forvalue i=20(1)24{
	gen AFR_min`i'82=0.237
}

forvalue i=25(1)29{
	gen AFR_min`i'82=0.178
}

forvalue i=30(1)34{
	gen AFR_min`i'82=0.044
}


forvalue i=35(1)39{
	gen AFR_min`i'82=0.028
}

forvalue i=40(1)44{
	gen AFR_min`i'82=0.018
}

forvalue i=45(1)49{
	gen AFR_min`i'82=0.000
}



*jiangxi 1982
forvalue i=15(1)19{
	gen AFR_gan`i'82=0.046
}

forvalue i=20(1)24{
	gen AFR_gan`i'82=0.229
}

forvalue i=25(1)29{
	gen AFR_gan`i'82=0.177
}

forvalue i=30(1)34{
	gen AFR_gan`i'82=0.060
}


forvalue i=35(1)39{
	gen AFR_gan`i'82=0.050
}

forvalue i=40(1)44{
	gen AFR_gan`i'82=0.010
}

forvalue i=45(1)49{
	gen AFR_gan`i'82=0.003
}





*shandong 1982
forvalue i=15(1)19{
	gen AFR_lu`i'82=0.004
}

forvalue i=20(1)24{
	gen AFR_lu`i'82=0.149
}

forvalue i=25(1)29{
	gen AFR_lu`i'82=0.199
}

forvalue i=30(1)34{
	gen AFR_lu`i'82=0.049
}


forvalue i=35(1)39{
	gen AFR_lu`i'82=0.012
}

forvalue i=40(1)44{
	gen AFR_lu`i'82=0.003
}

forvalue i=45(1)49{
	gen AFR_lu`i'82=0.000
}




*henan 1982
forvalue i=15(1)19{
	gen AFR_henan`i'82=0.007
}

forvalue i=20(1)24{
	gen AFR_henan`i'82=0.157
}

forvalue i=25(1)29{
	gen AFR_henan`i'82=0.210
}

forvalue i=30(1)34{
	gen AFR_henan`i'82=0.072
}


forvalue i=35(1)39{
	gen AFR_henan`i'82=0.026
}

forvalue i=40(1)44{
	gen AFR_henan`i'82=0.007
}

forvalue i=45(1)49{
	gen AFR_henan`i'82=0.001
}




*hubei 1982
forvalue i=15(1)19{
	gen AFR_e`i'82=0.017
}

forvalue i=20(1)24{
	gen AFR_e`i'82=0.197
}

forvalue i=25(1)29{
	gen AFR_e`i'82=0.156
}

forvalue i=30(1)34{
	gen AFR_e`i'82=0.047
}


forvalue i=35(1)39{
	gen AFR_e`i'82=0.013
}

forvalue i=40(1)44{
	gen AFR_e`i'82=0.012
}

forvalue i=45(1)49{
	gen AFR_e`i'82=0.000
}



*hunan 1982
forvalue i=15(1)19{
	gen AFR_xiang`i'82=0.019
}

forvalue i=20(1)24{
	gen AFR_xiang`i'82=0.258
}

forvalue i=25(1)29{
	gen AFR_xiang`i'82=0.265
}

forvalue i=30(1)34{
	gen AFR_xiang`i'82=0.060
}


forvalue i=35(1)39{
	gen AFR_xiang`i'82=0.025
}

forvalue i=40(1)44{
	gen AFR_xiang`i'82=0.017
}

forvalue i=45(1)49{
	gen AFR_xiang`i'82=0.003
}




*guangdong 1982

forvalue i=15(1)19{
	gen AFR_yue`i'82=0.025
}

forvalue i=20(1)24{
	gen AFR_yue`i'82=0.174
}

forvalue i=25(1)29{
	gen AFR_yue`i'82=0.248
}

forvalue i=30(1)34{
	gen AFR_yue`i'82=0.096
}


forvalue i=35(1)39{
	gen AFR_yue`i'82=0.056
}

forvalue i=40(1)44{
	gen AFR_yue`i'82=0.012
}

forvalue i=45(1)49{
	gen AFR_yue`i'82=0.006
}



*guangxi 1982
forvalue i=15(1)19{
	gen AFR_gui`i'82=0.012
}

forvalue i=20(1)24{
	gen AFR_gui`i'82=0.213
}

forvalue i=25(1)29{
	gen AFR_gui`i'82=0.253
}

forvalue i=30(1)34{
	gen AFR_gui`i'82=0.162
}


forvalue i=35(1)39{
	gen AFR_gui`i'82=0.085
}

forvalue i=40(1)44{
	gen AFR_gui`i'82=0.020
}

forvalue i=45(1)49{
	gen AFR_gui`i'82=0.005
}



*sichuan 1982

forvalue i=15(1)19{
	gen AFR_chuan`i'82=0.012
}

forvalue i=20(1)24{
	gen AFR_chuan`i'82=0.232
}

forvalue i=25(1)29{
	gen AFR_chuan`i'82=0.193
}

forvalue i=30(1)34{
	gen AFR_chuan`i'82=0.040
}


forvalue i=35(1)39{
	gen AFR_chuan`i'82=0.017
}

forvalue i=40(1)44{
	gen AFR_chuan`i'82=0.011
}

forvalue i=45(1)49{
	gen AFR_chuan`i'82=0.001
}



*guizhou 1982
forvalue i=15(1)19{
	gen AFR_qian`i'82=0.028
}

forvalue i=20(1)24{
	gen AFR_qian`i'82=0.222
}

forvalue i=25(1)29{
	gen AFR_qian`i'82=0.293
}

forvalue i=30(1)34{
	gen AFR_qian`i'82=0.168
}


forvalue i=35(1)39{
	gen AFR_qian`i'82=0.136
}

forvalue i=40(1)44{
	gen AFR_qian`i'82=0.044
}

forvalue i=45(1)49{
	gen AFR_qian`i'82=0.015
}



*yunnan 1982
forvalue i=15(1)19{
	gen AFR_dian`i'82=0.026
}

forvalue i=20(1)24{
	gen AFR_dian`i'82=0.236
}

forvalue i=25(1)29{
	gen AFR_dian`i'82=0.235
}

forvalue i=30(1)34{
	gen AFR_dian`i'82=0.123
}


forvalue i=35(1)39{
	gen AFR_dian`i'82=0.094
}

forvalue i=40(1)44{
	gen AFR_dian`i'82=0.030
}

forvalue i=45(1)49{
	gen AFR_dian`i'82=0.013
}




*shaanxi 1982
forvalue i=15(1)19{
	gen AFR_shaan`i'82=0.016
}

forvalue i=20(1)24{
	gen AFR_shaan`i'82=0.237
}

forvalue i=25(1)29{
	gen AFR_shaan`i'82=0.186
}

forvalue i=30(1)34{
	gen AFR_shaan`i'82=0.045
}


forvalue i=35(1)39{
	gen AFR_shaan`i'82=0.019
}

forvalue i=40(1)44{
	gen AFR_shaan`i'82=0.003
}

forvalue i=45(1)49{
	gen AFR_shaan`i'82=0.003
}



*gansu 1982
forvalue i=15(1)19{
	gen AFR_gansu`i'82=0.051
}

forvalue i=20(1)24{
	gen AFR_gansu`i'82=0.183
}

forvalue i=25(1)29{
	gen AFR_gansu`i'82=0.206
}

forvalue i=30(1)34{
	gen AFR_gansu`i'82=0.044
}


forvalue i=35(1)39{
	gen AFR_gansu`i'82=0.019
}

forvalue i=40(1)44{
	gen AFR_gansu`i'82=0.031
}

forvalue i=45(1)49{
	gen AFR_gansu`i'82=0.004
}



*qinghai 1982
forvalue i=15(1)19{
	gen AFR_qinghai`i'82=0.046
}

forvalue i=20(1)24{
	gen AFR_qinghai`i'82=0.150
}

forvalue i=25(1)29{
	gen AFR_qinghai`i'82=0.230
}

forvalue i=30(1)34{
	gen AFR_qinghai`i'82=0.224
}


forvalue i=35(1)39{
	gen AFR_qinghai`i'82=0.153
}

forvalue i=40(1)44{
	gen AFR_qinghai`i'82=0.092
}

forvalue i=45(1)49{
	gen AFR_qinghai`i'82=0.000
}




*ningxia 1982
forvalue i=15(1)19{
	gen AFR_ning`i'82=0.016
}

forvalue i=20(1)24{
	gen AFR_ning`i'82=0.276
}

forvalue i=25(1)29{
	gen AFR_ning`i'82=0.246
}

forvalue i=30(1)34{
	gen AFR_ning`i'82=0.134
}


forvalue i=35(1)39{
	gen AFR_ning`i'82=0.034
}

forvalue i=40(1)44{
	gen AFR_ning`i'82=0.038
}

forvalue i=45(1)49{
	gen AFR_ning`i'82=0.024
}



*beijing
forvalue i=15(1)49{
	gen dAFR_8268_jing`i'=AFR_jing`i'82-AFR_jing`i'llp
}

forv i=15(1)49{
		gen dffp_`i'8268=dAFR_8268_jing`i'*index_`i'llp if temp==4
}



*tianjin
forvalue i=15(1)49{
	gen dAFR_8268_jin`i'=AFR_jin`i'82-AFR_jin`i'llp
}

forv i=15(1)49{
		replace dffp_`i'8268=dAFR_8268_jin`i'*index_`i'llp if temp==7
}



*hebei
forvalue i=15(1)49{
	gen dAFR_8268_ji`i'=AFR_ji`i'82-AFR_ji`i'llp
}

forv i=15(1)49{
		replace dffp_`i'8268=dAFR_8268_ji`i'*index_`i'llp if temp==17
}



*Shanxi
forvalue i=15(1)49{
	gen dAFR_8268_shan`i'=AFR_shan`i'82-AFR_shan`i'llp
}


forv i=15(1)49{
		replace dffp_`i'8268=dAFR_8268_shan`i'*index_`i'llp if temp==11
}



*inner
forvalue i=15(1)49{
	gen dAFR_8268_inner`i'=AFR_inner`i'82-AFR_inner`i'llp
}


forv i=15(1)49{
		replace dffp_`i'8268=dAFR_8268_inner`i'*index_`i'llp if temp==3
}


*zhejiang
forvalue i=15(1)49{
	gen dAFR_8268_zhe`i'=AFR_zhe`i'82-AFR_zhe`i'llp
}


forv i=15(1)49{
		replace dffp_`i'8268=dAFR_8268_zhe`i'*index_`i'llp if temp==19
}



*jiangsu
forvalue i=15(1)49{
	gen dAFR_8268_su`i'=AFR_su`i'82-AFR_su`i'llp
}

forv i=15(1)49{
		replace dffp_`i'8268=dAFR_8268_su`i'*index_`i'llp if temp==15
}



*shanghai
forvalue i=15(1)49{
	gen dAFR_8268_hu`i'=AFR_hu`i'82-AFR_hu`i'llp
}


forv i=15(1)49{
		replace dffp_`i'8268=dAFR_8268_hu`i'*index_`i'llp if temp==1
}


*heilongjiang

forvalue i=15(1)49{
	gen dAFR_8268_hei`i'=AFR_hei`i'82-AFR_hei`i'llp
}

forv i=15(1)49{
		replace dffp_`i'8268=dAFR_8268_hei`i'*index_`i'llp if temp==31
}



*jilin
forvalue i=15(1)49{
	gen dAFR_8268_jilin`i'=AFR_jilin`i'82-AFR_jilin`i'llp
}

forv i=15(1)49{
		replace dffp_`i'8268=dAFR_8268_jilin`i'*index_`i'llp if temp==5
}


*liaoning
forvalue i=15(1)49{
	gen dAFR_8268_liao`i'=AFR_liao`i'82-AFR_liao`i'llp
}

forv i=15(1)49{
		replace dffp_`i'8268=dAFR_8268_liao`i'*index_`i'llp if temp==27
}



*anhui
forvalue i=15(1)49{
	gen dAFR_8268_wan`i'=AFR_wan`i'82-AFR_wan`i'llp
}

forv i=15(1)49{
		replace dffp_`i'8268=dAFR_8268_wan`i'*index_`i'llp if temp==9
}




*fujian
forvalue i=15(1)49{
	gen dAFR_8268_min`i'=AFR_min`i'82-AFR_min`i'llp
}

forv i=15(1)49{
		replace dffp_`i'8268=dAFR_8268_min`i'*index_`i'llp if temp==24
}



*jiangxi
forvalue i=15(1)49{
	gen dAFR_8268_gan`i'=AFR_gan`i'82-AFR_gan`i'llp
}

forv i=15(1)49{
		replace dffp_`i'8268=dAFR_8268_gan`i'*index_`i'llp if temp==16
}




*shandong
forvalue i=15(1)49{
	gen dAFR_8268_lu`i'=AFR_lu`i'82-AFR_lu`i'llp
}

forv i=15(1)49{
		replace dffp_`i'8268=dAFR_8268_lu`i'*index_`i'llp if temp==10
}



*henan
forvalue i=15(1)49{
	gen dAFR_8268_henan`i'=AFR_henan`i'82-AFR_henan`i'llp
}

forv i=15(1)49{
		replace dffp_`i'8268=dAFR_8268_henan`i'*index_`i'llp if temp==18
}





*hubei

forvalue i=15(1)49{
	gen dAFR_8268_e`i'=AFR_e`i'82-AFR_e`i'llp
}


forv i=15(1)49{
		replace dffp_`i'8268=dAFR_8268_e`i'*index_`i'llp if temp==21
}




*hunan

forvalue i=15(1)49{
	gen dAFR_8268_xiang`i'=AFR_xiang`i'82-AFR_xiang`i'llp
}


forv i=15(1)49{
		replace dffp_`i'8268=dAFR_8268_xiang`i'*index_`i'llp if temp==22
}




*guangdong

forvalue i=15(1)49{
	gen dAFR_8268_yue`i'=AFR_yue`i'82-AFR_yue`i'llp
}

forv i=15(1)49{
		replace dffp_`i'8268=dAFR_8268_yue`i'*index_`i'llp if temp==12
}



*guangxi

forvalue i=15(1)49{
	gen dAFR_8268_gui`i'=AFR_gui`i'82-AFR_gui`i'llp
}

forv i=15(1)49{
		replace dffp_`i'8268=dAFR_8268_gui`i'*index_`i'llp if temp==13
}



*sichuan

forvalue i=15(1)49{
	gen dAFR_8268_chuan`i'=AFR_chuan`i'82-AFR_chuan`i'llp
}

forv i=15(1)49{
		replace dffp_`i'8268=dAFR_8268_chuan`i'*index_`i'llp if temp==6
}



*guizhou
forvalue i=15(1)49{
	gen dAFR_8268_qian`i'=AFR_qian`i'82-AFR_qian`i'llp
}

forv i=15(1)49{
		replace dffp_`i'8268=dAFR_8268_qian`i'*index_`i'llp if temp==26
}


*yunnan
forvalue i=15(1)49{
	gen dAFR_8268_dian`i'=AFR_dian`i'82-AFR_dian`i'llp
}

forv i=15(1)49{
		replace dffp_`i'8268=dAFR_8268_dian`i'*index_`i'llp if temp==2
}



*shaanxi
forvalue i=15(1)49{
	gen dAFR_8268_shaan`i'=AFR_shaan`i'82-AFR_shaan`i'llp
}


forv i=15(1)49{
		replace dffp_`i'8268=dAFR_8268_shaan`i'*index_`i'llp if temp==29
}


*gansu
forvalue i=15(1)49{
	gen dAFR_8268_gansu`i'=AFR_gansu`i'82-AFR_gansu`i'llp
}


forv i=15(1)49{
		replace dffp_`i'8268=dAFR_8268_gansu`i'*index_`i'llp if temp==23
}



*qinghai
forvalue i=15(1)49{
	gen dAFR_8268_qinghai`i'=AFR_qinghai`i'82-AFR_qinghai`i'llp
}


forv i=15(1)49{
		replace dffp_`i'8268=dAFR_8268_qinghai`i'*index_`i'llp if temp==30
}



*ningxia
forvalue i=15(1)49{
	gen  dAFR_8268_ning`i'=AFR_ning`i'82-AFR_ning`i'llp
}

forv i=15(1)49{
		replace dffp_`i'8268=dAFR_8268_ning`i'*index_`i'llp if temp==8
}



egen dffp_8268=rowtotal(dffp_158268 dffp_168268 dffp_178268 dffp_188268 dffp_198268 dffp_208268 dffp_218268 dffp_228268 dffp_238268 dffp_248268 dffp_258268 dffp_268268 dffp_278268 dffp_288268 dffp_298268 dffp_308268 dffp_318268 dffp_328268 dffp_338268 dffp_348268 dffp_358268 dffp_368268 dffp_378268 dffp_388268 dffp_398268 dffp_408268 dffp_418268 dffp_428268 dffp_438268 dffp_448268 dffp_458268 dffp_468268 dffp_478268 dffp_488268 dffp_498268)

replace dffp_8268=. if temp==14 /*xinjiang*/
replace dffp_8268=. if temp==20/*hainan*/
replace dffp_8268=. if temp==25 /*xizang*/
replace dffp_8268=. if temp==28/*chongqing*/

*spouse



*beijing
forv i=15(1)49{
		gen spdffp_`i'8268=dAFR_8268_jing`i'*index_`i'llps if temp==4
}


*tianjin


forv i=15(1)49{
		replace spdffp_`i'8268=dAFR_8268_jin`i'*index_`i'llps if temp==7
}



*hebei


forv i=15(1)49{
		replace spdffp_`i'8268=dAFR_8268_ji`i'*index_`i'llps if temp==17
}



*Shanxi


forv i=15(1)49{
		replace spdffp_`i'8268=dAFR_8268_shan`i'*index_`i'llps if temp==11
}



*inner


forv i=15(1)49{
		replace spdffp_`i'8268=dAFR_8268_inner`i'*index_`i'llps if temp==3
}


*zhejiang
forv i=15(1)49{
		replace spdffp_`i'8268=dAFR_8268_zhe`i'*index_`i'llps if temp==19
}



*jiangsu

forv i=15(1)49{
		replace spdffp_`i'8268=dAFR_8268_su`i'*index_`i'llps if temp==15
}



*shanghai

forv i=15(1)49{
		replace spdffp_`i'8268=dAFR_8268_hu`i'*index_`i'llps if temp==1
}


*heilongjiang

forv i=15(1)49{
		replace spdffp_`i'8268=dAFR_8268_hei`i'*index_`i'llps if temp==31
}



*jilin

forv i=15(1)49{
		replace spdffp_`i'8268=dAFR_8268_jilin`i'*index_`i'llps if temp==5
}


*liaoning

forv i=15(1)49{
		replace spdffp_`i'8268=dAFR_8268_liao`i'*index_`i'llps if temp==27
}



*anhui

forv i=15(1)49{
		replace spdffp_`i'8268=dAFR_8268_wan`i'*index_`i'llps if temp==9
}




*fujian

forv i=15(1)49{
		replace spdffp_`i'8268=dAFR_8268_min`i'*index_`i'llps if temp==24
}



*jiangxi


forv i=15(1)49{
		replace spdffp_`i'8268=dAFR_8268_gan`i'*index_`i'llps if temp==16
}




*shandong

forv i=15(1)49{
		replace spdffp_`i'8268=dAFR_8268_lu`i'*index_`i'llps if temp==10
}



*henan


forv i=15(1)49{
		replace spdffp_`i'8268=dAFR_8268_henan`i'*index_`i'llps if temp==18
}


*hubei



forv i=15(1)49{
		replace spdffp_`i'8268=dAFR_8268_e`i'*index_`i'llps if temp==21
}




*hunan


forv i=15(1)49{
		replace spdffp_`i'8268=dAFR_8268_xiang`i'*index_`i'llps if temp==22
}




*guangdong

forv i=15(1)49{
		replace spdffp_`i'8268=dAFR_8268_yue`i'*index_`i'llps if temp==12
}



*guangxi

forv i=15(1)49{
		replace spdffp_`i'8268=dAFR_8268_gui`i'*index_`i'llps if temp==13
}



*sichuan

forv i=15(1)49{
		replace spdffp_`i'8268=dAFR_8268_chuan`i'*index_`i'llps if temp==6
}



*guizhou

forv i=15(1)49{
		replace spdffp_`i'8268=dAFR_8268_qian`i'*index_`i'llps if temp==26
}




*yunnan

forv i=15(1)49{
		replace spdffp_`i'8268=dAFR_8268_dian`i'*index_`i'llps if temp==2
}



*shaanxi


forv i=15(1)49{
		replace spdffp_`i'8268=dAFR_8268_shaan`i'*index_`i'llps if temp==29
}


*gansu


forv i=15(1)49{
		replace spdffp_`i'8268=dAFR_8268_gansu`i'*index_`i'llps if temp==23
}



*qinghai
forv i=15(1)49{
		replace spdffp_`i'8268=dAFR_8268_qinghai`i'*index_`i'llps if temp==30
}



*ningxia
forv i=15(1)49{
		replace spdffp_`i'8268=dAFR_8268_ning`i'*index_`i'llps if temp==8
}



egen spdffp_8268=rowtotal(spdffp_158268 spdffp_168268 spdffp_178268 spdffp_188268 spdffp_198268 spdffp_208268 spdffp_218268 spdffp_228268 spdffp_238268 spdffp_248268 spdffp_258268 spdffp_268268 spdffp_278268 spdffp_288268 spdffp_298268 spdffp_308268 spdffp_318268 spdffp_328268 spdffp_338268 spdffp_348268 spdffp_358268 spdffp_368268 spdffp_378268 spdffp_388268 spdffp_398268 spdffp_408268 spdffp_418268 spdffp_428268 spdffp_438268 spdffp_448268 spdffp_458268 spdffp_468268 spdffp_478268 spdffp_488268 spdffp_498268)

replace spdffp_8268=. if temp==14 /*xinjiang*/
replace spdffp_8268=. if temp==20/*hainan*/
replace spdffp_8268=. if temp==25 /*xizang*/
replace spdffp_8268=. if temp==28/*chongqing*/


*This is the PEI used in main analysis
gen dffp_wife8268=-dffp_8268 if male==0
replace dffp_wife8268=-spdffp_8268 if male==1



rename temp p


save JIR-Sep2024.dta,replace














